﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using core;

namespace comix
{
    public class Author : SiteItemSingle,ISiteItemMember
    {
        #region ISiteItemMember Members

        private string m_first_name;
        private string m_mid_name;
        private string m_last_name;

        public string FullName
        {
            get
            {
                string s = "";
                if (m_first_name.Length > 0)
                    s += m_first_name + " ";
                if (m_mid_name.Length > 0)
                    s += m_mid_name + " ";
                s += m_last_name;
                return s;
            }
        }

        public Author()
        {
            m_com.CommandText = "SELECT aut_firstname, aut_midname, aut_lastname FROM Authors WHERE aut_id = @aut_id";
        }

        public void FillMember(System.Data.SqlClient.SqlDataReader rdr)
        {
            Id = (int)rdr["aut_id"];
            m_first_name = rdr.IsDBNull(rdr.GetOrdinal("aut_firstname"))?"":(string)rdr["aut_firstname"];
            m_mid_name = rdr.IsDBNull(rdr.GetOrdinal("aut_midname")) ? "" : (string)rdr["aut_midname"];
            m_last_name = (string)rdr["aut_lastname"];
        }

        #endregion

        public override void DoFill(System.Data.SqlClient.SqlDataReader rdr)
        {
            Id = (int)rdr["aut_id"];
            m_first_name = rdr.IsDBNull(rdr.GetOrdinal("aut_firstname")) ? "" : (string)rdr["aut_firstname"];
            m_mid_name = rdr.IsDBNull(rdr.GetOrdinal("aut_midname")) ? "" : (string)rdr["aut_midname"];
            m_last_name = (string)rdr["aut_lastname"];
        }

        public override void SetSelectParameters()
        {
            m_com.Parameters.Clear();
            m_com.Parameters.Add(new System.Data.SqlClient.SqlParameter("@aut_id", Id));
        }
    }
}
